package com.neusoft.service.impl;

import com.neusoft.entity.CheckRequest;
import com.neusoft.entity.MedicalTechnology;
import com.neusoft.mapper.CheckRequestMapper;
import com.neusoft.mapper.MedicalTechnologyDtoMapper;
import com.neusoft.mapper.MedicalTechnologyMapper;
import com.neusoft.service.CheckRequestService;
import com.neusoft.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author akemihomurasama
 */
@Service
public class CheckRequestServiceImpl implements CheckRequestService {
    @Autowired
    private CheckRequestMapper checkRequestMapper;
    @Autowired
    private MedicalTechnologyDtoMapper medicalTechnologyDtoMapper;

    /**
     * 医生添加检查申请
     *
     * @param checkRequest 申请信息
     * @return 申请结果
     */
    @Override
    public Result addCheck(CheckRequest checkRequest) {
        checkRequest.setCreationTime(new Date());
        checkRequest.setCheckState("已开立");
        checkRequestMapper.addCheck(checkRequest);
        return Result.ok();
    }

    /**
     * 根据患者id查询患者已开立的检查申请
     *
     * @param registerId 患者id
     * @return 申请列表
     */
    @Override
    public Result queryCheckReqListById(int registerId) {
        return Result.ok(checkRequestMapper.queryCheckReqListById(registerId));
    }

    /**
     * 根据检查申请的状态查询申请信息
     *
     * @param checkState 检查申请的状态
     * @return 申请列表
     */
    @Override
    public Result queryReqByState(String checkState) {
        return Result.ok(checkRequestMapper.queryReqByState(checkState));
    }

    /**
     * 查询患者已缴费的检查申请的医技项目，同时查询检查申请id
     *
     * @param registerId 患者id
     * @return 医技项目列表，检查申请id
     */
    @Override
    public Result queryTechByPatient(int registerId, String checkState) {
        return Result.ok(medicalTechnologyDtoMapper.queryTechByIdListWithCheckId(registerId, checkState));
    }

    /**
     * 患者开始检查业务
     *
     * @param id         检查申请id
     * @param employeeId 医生id
     * @return 更新结果
     */
    @Override
    public Result patientBeginCheck(int id, int employeeId) {
        CheckRequest checkRequest = new CheckRequest();
        checkRequest.setId(id);
        checkRequest.setCheckEmployeeId(employeeId);
        checkRequest.setCheckTime(new Date());
        checkRequest.setCheckState("执行完成");
        checkRequestMapper.updateCheckReq(checkRequest);
        return Result.ok();
    }

    /**
     * 患者检查完成后更新患者检查申请的信息
     *
     * @param checkRequest 信息
     * @return 跟新结果
     */
    @Override
    public Result patientUpdateCheckRes(CheckRequest checkRequest) {
        checkRequestMapper.updateCheckReq(checkRequest);
        return Result.ok();
    }

    /**
     * 根据检查申请id查询检查申请
     *
     * @param id 检查申请id
     * @return 检查申请信息
     */
    @Override
    public Result queryCheckReqById(Integer id) {
        return Result.ok(checkRequestMapper.queryCheckReqById(id));
    }

    /**
     * 查询患者所有检查项目
     *
     * @param registerId 患者id
     * @return 检查项目列表
     */
    @Override
    public Result queryCheckByRegisterId(int registerId) {
        return Result.ok(medicalTechnologyDtoMapper.queryCheckTechListByRegisterId(registerId));
    }


}
